<template>
  <div class="boxContent">
    <div class="appBox">
      <div class="searchList">
        <el-form :model="state.params"
                 ref="FormInstance "
                 class="boxFrom">
          <div class="searchBox">
            <template v-for="(item, index) in state.totalInputColumns"
                      :key="index">
              <el-form-item v-if="item.type == 'input'">
                <el-input v-model="state.params[item.key]"
                          :placeholder="item.label"></el-input>
              </el-form-item>
              <el-form-item v-if="item.type == 'select'">
                <el-select v-model="state.params[item.key]"
                           :placeholder="item.label"
                           clearable
                           v-if="item.key == 'cid'">
                  <el-option />
                </el-select>

                <el-cascader v-model="state.params[item.key]"
                             :options="state.propsCity"
                             :props="state.props"
                             :placeholder="item.label"
                             clearable
                             v-if="item.key == 'city'" />
              </el-form-item>
              <el-form-item v-if="item.type == 'time'">
                <el-date-picker v-model="state.params[item.key]"
                                type="daterange"
                                value-format="YYYY-MM-DD"
                                start-placeholder="开始日期"
                                range-separator="至"
                                end-placeholder="结束日期"
                                :placeholder="item.label" />
              </el-form-item>
            </template>
          </div>

          <el-form-item class="btns">
            <el-button v-preventReClick
                       type="primary"
                       plain
                       @click="methods.handleAction('query')">搜索</el-button>
            <el-button v-preventReClick
                       @click="methods.handleAction('reset')">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="tabaleBox">
        <el-table border
                  v-loading="state.loading"
                  :data="state.tableData"
                  style="width: 100%"
                  :header-cell-style="{ color: '#000' }">

          <el-table-column prop="createdAt"
                           label="操作时间"
                           show-overflow-tooltip
                           align="center"
                           width="180">
          </el-table-column>
          <el-table-column prop="operName"
                           label="操作员工"
                           show-overflow-tooltip
                           align="center"
                           width="110">
          </el-table-column>
          <el-table-column prop="title"
                           label="操作事项"
                           show-overflow-tooltip
                           align="left">
          </el-table-column>

        </el-table>
      </div>
      <div class="pagination">
        <el-pagination background
                       v-model:current-page="state.params.pageNum"
                       v-model:page-size="state.params.pageSize"
                       :page-sizes="[10, 20, 30, 50]"
                       layout="total, sizes, prev, pager, next, jumper"
                       :total="state.totalSize"
                       @size-change="methods.handleSizeChange"
                       @current-change="methods.handleCurrentChange" />
      </div>

    </div>
  </div>
</template>

<script setup>
import {
  ref,
  onMounted,
  reactive,
  toRefs,
  defineComponent,
  getCurrentInstance,
} from "vue";
import { ElMessage, ElLoading, ElMessageBox } from "element-plus";
import { useRouter } from "vue-router";
const router = useRouter();
const app = getCurrentInstance()?.proxy;
const initState = () => {
  return {
    loading: false,
    totalSize: 0,
    tableData: [],
    params: {
      pageNum: 1,
      pageSize: 10,

    },
    totalInputColumns: [
      { key: "operName", label: "操作员工", type: "input" },
      { key: "operateTime", label: "操作时间", type: "time" },
    ],
  };
};
const state = reactive(initState());
onMounted(() => {
  methods.getDataList();
});
const methods = {

  handleAction (type, data) {
    switch (type) {

      case "query": //查询
        methods.getDataList();
        break;
      case "reset": // 重置
        state.params = initState().params;
        break;
    }
  },
  getDataList () {
    // state.tableData = [
    //   { time: '2020-09-18 16:10', name: 'admin', matter: '新增轮播图' },
    //   { time: '2020-09-18 16:20', name: 'admin', matter: '删除轮播图' },
    //   { time: '2020-09-18 16:30', name: 'admin', matter: '编辑轮播图' },
    //   { time: '2020-09-18 16:40', name: 'admin', matter: '新增角色' },
    //   { time: '2020-09-18 16:50', name: 'admin', matter: '删除角色' },
    //   { time: '2020-09-18 16:55', name: 'admin', matter: '编辑账号' },
    //   { time: '2020-09-18 17:12', name: 'admin', matter: '新增账号' },
    //   { time: '2020-09-18 17:50', name: 'admin', matter: '删除账号' },
    //   { time: '2020-09-18 19:20', name: 'admin', matter: '审核企业认证' },
    //   { time: '2020-09-18 20:25', name: 'admin', matter: '审核企业认证' },
    //   // { time: '2020-09-18 21:59', name: 'admin', matter: '审核企业认证' },
    // ]
    // state.totalSize = state.tableData.length
    state.loading = true

    app.$http
      .post("/sysOperLog/pageList", state.params)
      .then((res) => {
        state.tableData = res.data.list;
        state.totalSize = res.data.total;
        state.loading = false
      }).catch(() => {
        state.loading = false
      })
  },
  //分页变化
  handleSizeChange () {
    state.params.pageNum = 1;
    methods.getDataList();
  },
  //表格翻页
  handleCurrentChange () {
    methods.getDataList();
  },
};
</script>

<style lang="scss" scoped>
.appBox {
  background: #fff;
  border-radius: 5px;
  padding: 20px;
  height: calc(100% - 20px);
  width: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  .tabaleBox {
    overflow: hidden;
    flex: 1;
  }
  .btnsDatil {
    color: #0079fe;
    cursor: pointer;
  }
  .pagination {
    margin-top: 20px;
    height: 50px;
    display: flex;
    justify-content: flex-end;
  }
  ::v-deep(.el-dialog__body) {
    max-height: 380px;
  }
  .imgs {
    flex-wrap: wrap;
    .forbox {
      // width: 150px;
      height: 150px;
      margin: 10px 0 0 10px;
    }
    .imgBox {
      height: 100%;
      width: auto;
    }
    .videoBox {
      width: auto;
      height: 100%;
    }
  }

  // .imgs .forbox:nth-child(4n + 1) {
  //   margin-left: 0;
  // }
}
</style>
